package cn.dly.login.controller;

import cn.dly.login.utils.R;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags="支付")
@RequestMapping("/sys/api")
@CrossOrigin
public class PayController {


    @ApiOperation("扫码付钱")
    @RequestMapping( value = "/pay", method = { RequestMethod.POST } )
    public String back(String info,String id,String amount) throws Exception {

        Config config=new Config();
        config.protocol = "https";
        config.signType = "RSA2";
        config.merchantPrivateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCyZpJLzgN3NEWdfuhMxyipvjr36AcCFRwHPTdvHwloI0iq5GB3k0P+BicdcRoIHUUscqmMgCmc2h4ryplJcXdmYBXXctbsGvwyN3SIcISsznY5u7Tn2qpF7zQmtwvYgOJYezQp7H3qb++L9QUSg9sN6gTBR79oNKkBSmej91CFTU+OE+Pc+xaVOjXB2a5stW6dx7TmXeqJtM7RrbuzF/OogYcY/KYbFEHpIzekUgxD4r4pAZpEp4Ly3zJpLNL6M5tmJE3+cOqMewquPJg041b7HBu/oXaxArdwYWS5XfxIfmJE1mpzmzPMwuEOzrHIrtcmZIKCS//2C8J4JbMoKD11AgMBAAECggEALlExFFtFTRKWLGDBgQWICiHof2qPPzwpzbtYBBKjx5S5jhzC6uiiE3aXey5dGtQ2nGacnGy94QpEIQx1pbq+zCaQJSKcqCoNZiA9shq8Z30m9rBENJnx8Tw8ZvzJJ4m2ulAqZ+QNgOtU3xpbGcZ//enPGDs/d5eMdVhS9iAEmMbdV1XBvULfKHtbSjsG/LgxP/qsbiMIZPE72SnJWO3dABVwfHTLzF/eNKfgTAx6yDqPbw2kcqd7p6Y2+KkdbAkAVoCr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9K+7Yb5S8c67I3Fo12BznfTtItbw5/4jBmY1oxWT7ryEyXAT7lXPkk9oCRyQRH3V1mI5cF0pq+Z1ylbLQt8kFjuGv2UmgcoTxS+/Axx+2X0tysZHUcETGAFe8Dec+Xq6J3u8CPdLgtzSvzz7P6zCFvcLVlUhmSbTdFZLVy6NsWGPTpHUbxk4zQuLfxm6rUmP4w+VVd/m1iw98jtpF0Bl7AJ/NwbTBx6b8u+9SjN/T0prvxvBr+u75jIx8qLNWUBjR0HyLcN05eC/pg02BGz5LR/fz1e5hi6mLs/F18ANT5YQQIDAQAB";
        config.gatewayHost="openapi.alipaydev.com";
        Factory.setOptions(config);
        AlipayTradePagePayResponse response = Factory.Payment
                .Page()
                .pay(info, id,
                        amount, "www.baidu.com");
        return response.body;
    }

    @ApiOperation("查询支付状态")
    @RequestMapping( value = "/querypay", method = { RequestMethod.POST } )
    public R query(String id) throws Exception {
        Config config=new Config();
        config.protocol = "https";
        config.signType = "RSA2";
        config.merchantPrivateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCyZpJLzgN3NEWdfuhMxyipvjr36AcCFRwHPTdvHwloI0iq5GB3k0P+BicdcRoIHUUscqmMgCmc2h4ryplJcXdmYBXXctbsGvwyN3SIcISsznY5u7Tn2qpF7zQmtwvYgOJYezQp7H3qb++L9QUSg9sN6gTBR79oNKkBSmej91CFTU+OE+Pc+xaVOjXB2a5stW6dx7TmXeqJtM7RrbuzF/OogYcY/KYbFEHpIzekUgxD4r4pAZpEp4Ly3zJpLNL6M5tmJE3+cOqMewquPJg041b7HBu/oXaxArdwYWS5XfxIfmJE1mpzmzPMwuEOzrHIrtcmZIKCS//2C8J4JbMoKD11AgMBAAECggEALlExFFtFTRKWLGDBgQWICiHof2qPPzwpzbtYBBKjx5S5jhzC6uiiE3aXey5dGtQ2nGacnGy94QpEIQx1pbq+zCaQJSKcqCoNZiA9shq8Z30m9rBENJnx8Tw8ZvzJJ4m2ulAqZ+QN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UCqptvFoy0=";
        config.appId="2021000117659809";
        config.alipayPublicKey="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1f6/2yAY42E2hpUNjfkMbNH4ByP8eNNXyUVuknhnq9K+7Yb5S8c67I3Fo12BznfTtItbw5/4jBmY1oxWT7ryEyXAT7lXPkk9oCRyQRH3V1mI5cF0pq+Z1ylbLQt8kFjuGv2UmgcoTxS+/Axx+2X0tysZHUcETGAFe8Dec+Xq6J3u8CPdLgtzSvzz7P6zCFvcLVlUhmSbTdFZLVy6NsWGPTpHUbxk4zQuLfxm6rUmP4w+VVd/m1iw98jtpF0Bl7AJ/NwbTBx6b8u+9SjN/T0prvxvBr+u75jIx8qLNWUBjR0HyLcN05eC/pg02BGz5LR/fz1e5hi6mLs/F18ANT5YQQIDAQAB";
        config.gatewayHost="openapi.alipaydev.com";
        Factory.setOptions(config);
        String flag=Factory.Payment.Common().query(id).getMsg();
        if(flag.equals("Success")){
            return R.ok();
        }
        else{
            return R.error();
        }
    }

}
